package com.k2data.k2app.controller;

import com.k2data.k2app.response.CommonResultResponse;
import com.k2data.k2app.response.ResponseHelper;
import com.k2data.k2app.service.KmxRuleService;
import com.k2data.k2app.service.KmxService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author lidong9144@163.com 17-3-17.
 */
@RestController
@RequestMapping("/kmx")
public class KmxController {

    private final KmxService kmxService;
    private final KmxRuleService kmxRuleService;

    @Autowired
    public KmxController(KmxService kmxService, KmxRuleService kmxRuleService) {
        this.kmxService = kmxService;
        this.kmxRuleService = kmxRuleService;
    }

    @ApiOperation(value = "同步元数据到 KMX, 后台判断是新增 fieldGroup 还是添加 field")
    @GetMapping(value = "/meta2kmx")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "point_id", value = "monitorPointId", dataType = "Long", paramType = "query")
    })
    public ResponseEntity<CommonResultResponse> meta2Kmx(@RequestParam(value = "point_id", required = false) Long pointId) throws Exception {
        return ResponseHelper.success(kmxService.toKmx(pointId));
    }

    @ApiOperation(value = "同步测点阈值")
    @PostMapping(value = "/limit2kmx")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "rid", value = "rid", dataType = "Long", paramType = "query")
    })
    public ResponseEntity<CommonResultResponse> limit2Kmx(@RequestParam(value = "rid") Long rid) throws Exception {
        kmxRuleService.pushLimitCopy(rid);
        return ResponseHelper.success();
    }


    @ApiOperation(value = "同步测点阈值,临时接口，同步后续导入的测点的阈值")
    @PostMapping(value = "/limit2kmxV2")
    public ResponseEntity<CommonResultResponse> limit2KmxV2() throws Exception {
        kmxRuleService.pushDifferentPoint();
        return ResponseHelper.success();
    }
}
